
function Ship() {
	this.speed = 20;
	this.bulletPool = new Pool(60);
	var fireRate = 15;
	var counter = 0;
	this.collidableWith = "";
	this.type = "ship";

	this.init = function (x, y, width, height) {
		// Defualt variables
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.alive = true;
		this.isColliding = false;
		this.bulletPool.init("bullet");
	}

	this.draw = function () {
		this.context.drawImage(imageRepository.spaceship, this.x, this.y);
	};
	this.move = function () {
		counter++;
		// Determine if the action is move action
		if (KEY_STATUS.left || KEY_STATUS.right ||
			KEY_STATUS.down || KEY_STATUS.up) {
			// The ship moved, so erase it's current image so it can
			// be redrawn in it's new location
			this.context.clearRect(this.x, this.y, this.width, this.height);

			// Update x and y according to the direction to move and
			// redraw the ship. Change the else if's to if statements
			// to have diagonal movement.
			if (KEY_STATUS.left) {
				this.x -= this.speed
				if (this.x <= 0) // Kep player within the screen
					this.x = 0;
			} else if (KEY_STATUS.right) {
				this.x += this.speed
				if (this.x >= this.canvasWidth - this.width)
					this.x = this.canvasWidth - this.width;
			} else if (KEY_STATUS.up) {
				this.y -= this.speed
				if (this.y <= 0)
					this.y = 0;
			} else if (KEY_STATUS.down) {
				this.y += this.speed
				if (this.y >= this.canvasHeight - this.height)
					this.y = this.canvasHeight - this.height;
			}
		}
		// Redraw the ship
		if (!this.isColliding) {
			this.draw();
		} else {
			game.playerScore -= 20;
			console.log(game.playerScore);

			this.isColliding = false;
			game.explosion.get();

			this.draw();
		}

		if (KEY_STATUS.space && counter >= fireRate && !this.isColliding) {
			this.fire();
			counter = 0;
		}
	};

	/*
	 * Fires two bullets
	 */
	this.fire = function () {
		this.bulletPool.getTwo(this.x + 6, this.y, 10,
			this.x + 33, this.y, 10);
		game.laser.get();
	};
}
Ship.prototype = new Drawable();
